package com.project.controller;

import com.project.exception.BusinessException;
import com.project.pojo.Response;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author liuyi 
 * @Description
 * @Date 2022/3/10 21:48 
 * @Param  
 * @return 
 **/
@ControllerAdvice("com.project.controller")
public class ExceptionAdvice {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Response process(Exception e) {
        if(e.getClass() == BusinessException.class){
            return  Response.error(((BusinessException) e).getCode(),e.getMessage());
        }
        else {
            return Response.error(1,e.getMessage());
        }
    }
}
